#include <gtest/gtest.h>
#include "../mqserver/mq_binding.hpp"

mq::BindManager::Ptr bmp;
class My_Bind_Test : public testing::Environment 
{
public:
    void SetUp() override
    {
        bmp = std::make_shared<mq::BindManager>("./test-bind.db");
    }
    void TearDown() override
    {
        // bmp->clear();
    }
private:
    ;
};

TEST(My_Bind_Test,insert_test)
{
    ASSERT_EQ(bmp->bind("exchange1","queue1","listen.gossip.new",true),true);
    ASSERT_EQ(bmp->bind("exchange1","queue2","listen.haha.new#",true),true);
    ASSERT_EQ(bmp->bind("exchange2","queue2","eat.new#",true),true);
    ASSERT_EQ(bmp->bind("exchange2","queue1","eat.new#",true),true);
    // ASSERT_EQ(bmp->bind("exchange1","queue3","eat.new#",true),true);
    // ASSERT_EQ(bmp->bind("exchange2","queue3","eat.new#",true),true);
    ASSERT_EQ(bmp->bind("exchange3","queue3","eat.new#",true),true);
    ASSERT_EQ(bmp->size(),5);
}

TEST(My_Bind_Test,select_test)
{
    mq::mqbinding::Ptr mbp = bmp->getBinding("exchange1","queue1");
    ASSERT_EQ(mbp->exchange_name,std::string("exchange1"));
    ASSERT_EQ(mbp->queue_name,std::string("queue1"));
}

TEST(My_Bind_Test,exists_test)
{
    ASSERT_EQ(bmp->exists("exchange1","queue1"),true);
}

int main(int argc,char* argv[])
{
    testing::InitGoogleTest(&argc,argv);
    testing::AddGlobalTestEnvironment(new My_Bind_Test);
    RUN_ALL_TESTS();

    return 0;
}